<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class LoginController extends Controller
{
   public function index()
   {
      return view('home.login');
   }
   public function login(Request $request)
   {
//       dd($request);
//      验证用户名，密码是否正确
       $status = \Auth::attempt([
           'name'=>$request->name,
           'password' =>$request->password,
       ]);
       if ($status)
       {
           return redirect('/')->with('success','登录成功');
       } else{
           return back()->with('error','账号或密码错误');
       }
   }
   public function logout()
   {
      auth()->logout();
      return redirect(route('home.login'))->with('success','退出成功');
   }
}
